package com.example.basic.thread;

import java.text.ParseException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;
import java.util.function.Function;

public class CompletableFutureTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<String> future = new CompletableFuture<>();
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("CompletableFuture可以监控这个任务的执行");
                future.complete("任务返回结果");
            }
        }).start();
        System.out.println("---------1-----------");
//        future.
//        future.thenAccept(new Consumer<String>() {
//            @Override
//            public void accept(String s) {
//
//                System.out.println("返回结果 = " + s);
//                System.out.println("ThreadName = " + Thread.currentThread().getName());
//            }
//        }).exceptionally(new Function<Throwable, Void>() {
//            @Override
//            public Void apply(Throwable throwable) {
//                System.out.println("异常值 = " + throwable.getMessage());
//                System.out.println("ThreadName = " + Thread.currentThread().getName());
//                return null;
//            }
//        });
//        System.out.println("---------1-----------");
//        System.out.println(future.get());
        System.out.println("---------2-----------");
    }

}
